#include "frame_state.h"

FrameState::FrameState(QObject *parent) : Frame(19, 0x000032, parent) {}

QByteArray FrameState::EncodeToBytes() const
{
    QByteArray array = QByteArray(Size(), 0);
    throw std::runtime_error("Not implemented");
    (void)array;
    return array;
}

void FrameState::DecodeFromBytes(const QByteArray &array)
{
    speed = static_cast<float>(array[0]) / 200;
    this_mileage = static_cast<float>(array[1] | array[2] << 8) / 30'000;
    total_mileage = static_cast<float>(array[3] | array[4] << 8 | array[5] << 16 | array[6] << 24) / 1'000'000;
    current_speed_limit = static_cast<float>(array[7]) / 200;
    gear_feedback = static_cast<GearFeedback>((array[8] | 0b1110'0000) >> 5);
    steering_state = static_cast<SteeringState>((array[8] | 0b0001'1000) >> 3);
    emergency_mode = static_cast<EmergencyMode>((array[8] | 0b0000'0100) >> 2);
    control_mode = static_cast<ControlMode>(array[8] | 0b0000'0011);

    // TODO ....
    (void)array;
}

QString FrameState::GetFrameName() const
{
    return "State";
}
